package com.xkdx.guangguang.fragment.user;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.content.Context;

import com.xkdx.guangguang.module.network.AbsModule;
import com.xkdx.guangguang.module.statics.IConstants;

public class UserUnBindSinaModule extends AbsModule {

	JSONObject values;
	private Context context;
	private UserSharePrefence user_sp;
	public UnBindSinaInfo unbindUser;
	JSONArray jsonArray;
	JSONObject jsonObj;

	public UserUnBindSinaModule(Context context) {
		this.context = context;
	}

	@Override
	public void parseData() throws Exception {

		try {
			user_sp = new UserSharePrefence(context, IConstants.SP_USER);
			unbindUser = new UnBindSinaInfo();
			jsonArray = (JSONArray) result;
			jsonObj = (JSONObject) jsonArray.get(0);

			unbindUser = parserBindUserRgist(jsonObj.getJSONObject("Content"));

		} catch (Exception e) {

			throw e;
		}

	}

	private UnBindSinaInfo parserBindUserRgist(JSONObject unbind)
			throws Exception {

		try {
			JSONObject stut = (JSONObject) unbind.get("Result");
			unbindUser.setErrorCode(stut.getString("ErrorCode"));
			unbindUser.setMessage(stut.getString("Message"));
			unbindUser.setType(stut.getString("Type"));
			unbindUser.setStatus(stut.getString("Status"));

			// 将用户信息存到本地
			if ("Success".equals(stut.getString("Status"))) {
				user_sp.setSinaWeiboToken("");
				user_sp.setSinaWeiboNickName("");
				user_sp.setSinaWeiboUserID("");
				user_sp.setSinaWeiboExpireTime("");
			}
		} catch (JSONException e) {
			throw e;
		}
		return unbindUser;

	}

	public class UnBindSinaInfo {
		private String Type;
		private String Status;
		private String ErrorCode;
		private String Message;

		public String getType() {
			return Type;
		}

		public void setType(String type) {
			Type = type;
		}

		public String getStatus() {
			return Status;
		}

		public void setStatus(String status) {
			Status = status;
		}

		public String getErrorCode() {
			return ErrorCode;
		}

		public void setErrorCode(String errorCode) {
			ErrorCode = errorCode;
		}

		public String getMessage() {
			return Message;
		}

		public void setMessage(String message) {
			Message = message;
		}

	}

}
